<?php

namespace app\common\model\company;

use think\Model;

class Score extends Model
{
    protected $table = 'scores';
    protected $pk = 'Id';

     public function companyinfo()
    {
        return $this->hasOne('app\common\model\company\Company', 'CompanyId', 'CompanyId');
    }

    public function bussinfo()
    {
        return $this->hasOne('app\common\model\user\User', 'UserId', 'UId');
    }


    public function getInfoAttr($value)
    {
        $value = json_decode($value,true);
        return $value;
    }

    /**
 * 获取订单列表
 * @param  [type] $data    [主数据]
 * @param  string $type    [查询类型/hawa/buss]
 * @param  [type] $is_page [是否分页显示]
 * @return [type]          [description]
 */
    public static function usergetlist($data, $type = 'buss', $is_page = true)
    {
        $rdata = new Score;
        if ($type == 'buss') {
            $visible = ['Id', 'TouchTime', 'CompanyId', 'UserName', 'TouchUserName','companyinfo'=>['Name'],'Source','CompanyType','Level'];
        }else if ($type == 'mana') {
            $visible = ['Id', 'TouchTime', 'CompanyId', 'UserName', 'TouchUserName','companyinfo'=>['Name'],'Source','CompanyType','Level'];
        }else {
            return moerr('缺少参数');
        }
        if (!empty($data['field'])) {
            $visible = array_merge($data['field'], $visible);
        }

        $option = come_model_option($data, $rdata, $is_page);

        $rdata = $option['rdata'];
        $data  = $option['data'];

        if (!empty($data['field'])) {
            $rdata = $rdata->field($visible);
        }
        if (!empty($visible)) {
            $rdata = $rdata->visible($visible);
        }

        if (!$is_page) {
            $rdata = $rdata->limit(10);
        }
        $rdata = $rdata->with('companyinfo');
        $rdata = $rdata->select();

        $ndata['list'] = $rdata->toArray();

        if ($is_page) {
            $ndata['pageinfo'] = ['pageindex' => $data['pageindex'], 'pagemax' => $data['count']];
        }
        return $ndata;
    }
}